=begin
    close – 關閉檔案。跟你編輯器的 文件->儲存.. 是一樣的意思。
    read – 讀取檔案內容。你可以把結果賦給一個變數。
    readline – 讀取檔案文字中的一行。
    truncate – 清空文件，請小心使用該命令。
    write(stuff) – 將 stuff 寫入檔案。
=end

filename = ARGV.first
script = $0

puts "We're using #{script} to erase #{filename}."
puts "If you don't want that, hit CTRL-C (^C)."
puts "If you do want that, hit RETURN."

print "? "
STDIN.gets

puts "Opening the file..."
target = File.open(filename, 'w')

puts "Truncating the file.  Goodbye!"
target.truncate(target.size)

puts "Now I'm going to ask you for three lines."

print "line 1: "; line1 = STDIN.gets.chomp()
print "line 2: "; line2 = STDIN.gets.chomp()
print "line 3: "; line3 = STDIN.gets.chomp()

puts "I'm going to write these to the file."

target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")

puts "And finally, we close it."
target.close()
